package cz.acies.uniql.sql.functions;

import java.util.ArrayList;


import cz.acies.uniql.dialect.*;
import cz.acies.uniql.sql.UniQLExpr;
import cz.acies.uniql.sql.element.UniQLColumn;

public class SQLSpecFunc extends SQLFunc
{
	private static final long serialVersionUID = 589776052478655207L;
	
	private UniQLExpr sufix;
	
	public SQLSpecFunc() {
	}

	public SQLSpecFunc(Dialect dialect) {
		super(dialect);
	}

	public SQLSpecFunc(String name) {
		super();
		this.setName(name.toLowerCase());		
	}
	
	// -----  -----------------------------------------------------------------

	public SQLFunc addSufix(SQLFunc expr) {
		this.sufix = expr;
		this.sufix.setDialect(this.getDialect());
		return this;
	}
	
	public SQLFunc addParam(String column) {
		if (this.getParameters() == null) this.setParameters(new ArrayList<Object>());
		UniQLColumn expr = new UniQLColumn(column);
		return addParam(expr);
	}
	
	public SQLFunc addParam(UniQLExpr expr) {
		if (this.getParameters() == null) this.setParameters(new ArrayList<Object>());
		expr.setDialect(this.getDialect());
		this.getParameters().add(expr);		
		return this;
	}
	
	public String translate() throws Exception {
		String syntax = super.translate();
		if (this.sufix != null) {
			syntax += " "+sufix.translate(); 
		}
		return syntax;
	}
	
}
